#ifndef PLAYERITEMS_H
#define PLAYERITEMS_H
#include "gameboarditem.h"
#include "gameboardorganizer.h"
#include <QPainter>
#include "gs.h"

using namespace gs;

namespace gs
{
class TaoFieldBg : public GameBoardItem
{
public:
    TaoFieldBg(GameBoardOrganizer* parent = 0,int w = 0,int h = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
    int _width;
    int _height;
};

class TaoItem : public QGraphicsObject
{
public:
    TaoItem(GameBoardItem* parent = 0, gs::GSColor c = RED);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
    void setTaoPix(gs::GSColor c);
    static const int TAO_WIDTH = 44;
    static const int TAO_HEIGHT = 44;

    QPixmap _taoPix;
    int     _taoNum;
    gs::GSColor _taoColor;
};

class TaoSlot : public GameBoardItem
{
public:
    TaoSlot(GameBoardOrganizer* parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    static const int TSLOT_WIDTH = 44;
    static const int TSLOT_HEIGHT = 44;
protected:

};

class PlayerHead : public GameBoardItem
{
public:
    PlayerHead(GameBoardOrganizer* parent, QPixmap);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    static const int WIDTH = 120;
    static const int HEIGHT = 120;
protected:
    QPixmap _headPix;
};

class PlayerQi : public GameBoardItem
{
public:
    PlayerQi(GameBoardOrganizer* parent = 0,int qiNum = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    static const int QI_AREA_WIDTH = 60;
    static const int QI_AREA_HEIGHT = 44;
    static const int TEXT_WIDTH = 20;
    static const int TEXT_HEIGHT = 15;
    static const int GAP = 5;
protected:
    QPixmap _qiPix;
    QFont _font;
    int _qiNum;
};

class PlayerYin : public GameBoardItem
{
    Q_OBJECT
public:
    PlayerYin(GameBoardOrganizer* parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    static const int YIN_WIDTH = 44;
    static const int YIN_HEIGHT = 44;
protected:
    void mousePressEvent( QGraphicsSceneMouseEvent *event )
    {
        emit clicked();
    }
    QPixmap _yinPix;
signals:
    void clicked();
protected slots:


};

class PlayerBudd : public GameBoardItem
{
    //Q_OBJECT
public:
    PlayerBudd(GameBoardOrganizer* parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);    
    static const int BUDD_WIDTH = 44;
    static const int BUDD_HEIGHT = 44;
protected:
    //void mousePressEvent( QGraphicsSceneMouseEvent *event )
    //{
    //    emit clicked();
    //}
    QPixmap _buddPix;
//signals:
    //void clicked();
//protected slots:
};

class PlayerSkill : public GameBoardItem
{
    Q_OBJECT
public:
    PlayerSkill(GameBoardOrganizer* parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);    
    static const int SKILL_WIDTH = 44;
    static const int SKILL_HEIGHT = 44;
protected:
    void mousePressEvent( QGraphicsSceneMouseEvent *event);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    void setSkillInfo();
    QPixmap _skillPix;
    bool isUseable;
    Player* currentPlayer;
    PlayerSkillObject* currentSkill;
    GhostBoard* currentBoard;
signals:
protected slots:
    void sealSkill();
    void unsealSkill();
};

class ActionButton : public GameBoardItem
{
    //Q_OBJECT
public:
    ActionButton(GameBoardOrganizer* parent = 0,QString title = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    static const int BUTTON_WIDTH = 30;
    static const int BUTTON_HEIGHT = 30;
protected:
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    QPixmap _actPix;
    QString _title;
    QFont _font;

};

class MoveButton : public ActionButton
{
public:
    MoveButton(GameBoardOrganizer* parent = 0,QString title = 0);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
};

class ShopButton : public ActionButton
{
public:
    ShopButton(GameBoardOrganizer* parent = 0, QString title = 0);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
protected:
    Player* currentPlayer;
};

class FightButton : public ActionButton
{
public:
    FightButton(GameBoardOrganizer* parent = 0, QString title = 0);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
protected:
    Player* currentPlayer;
};

class PlayerTaoField : public GameBoardOrganizer
{
public:
    PlayerTaoField(GameTable* t,GameBoardOrganizer* b,Player* p );
    static const int FIELD_WIDTH = 244;
    static const int FIELD_HEIGHT = 196;
    Player* _pl;
protected:
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    void setTaoSlots();

    FrontTaoField* _frontTao;
    HiddenTaoField* _hiddenTao;
};

class FrontTaoField : public GameBoardOrganizer
{
    Q_OBJECT
public:
    FrontTaoField(GameTable* t,GameBoardOrganizer* b,Player* p );
    static const int FRONT_WIDTH = 244;
    static const int FRONT_HEIGHT = 48;
    Player* _pl;
protected:
    TaoFieldBg* _bg;
    QList<TaoItem*> frontTaos;
    void setFrontRow();
protected slots:
    void updateTao();


};

class HiddenTaoField : public GameBoardOrganizer
{
    Q_OBJECT
public:
    HiddenTaoField(GameTable* t,GameBoardOrganizer* b,Player* p);
    static const int HIDDEN_WIDTH = 244;
    static const int HIDDEN_HEIGHT = 148;
    Player* _pl;
protected:
    QList<TaoSlot*> _hiddenRow;
    QList<TaoItem*> hiddenTaos;
    TaoFieldBg* _bg;
    void setHiddenRow();
protected slots:
    void updateTao();
};

class PlayerBasic : public GameBoardOrganizer
{
public:
    PlayerBasic(GameTable* t,GameBoardOrganizer* b,Player* p );
    static const int BASIC_WIDTH = PlayerHead::WIDTH+10+ PlayerQi::QI_AREA_WIDTH+ PlayerYin::YIN_WIDTH
                                                +PlayerBudd::BUDD_WIDTH+PlayerSkill::SKILL_WIDTH;
    static const int BASIC_HEIGHT = 140;
    Player* _pl;
    void setItems();
protected:
    PlayerHead*     _ph;
    PlayerQi*       _pq;
    PlayerYin*      _py;
    PlayerBudd*     _pb;
    PlayerSkill*    _ps;
};

class PlayerAction : public GameBoardOrganizer
{
public:
    PlayerAction(GameTable* t,GameBoardOrganizer* b,Player* p);
    static const int ACTION_WIDTH = 170;
    static const int ACTION_HEIGHT = 44;
    static const int GAP = 4;
    void setActionButtons();
    Player* _pl;
protected:
    ActionButton* _moveAction;
    ActionButton* _shopAction;
    ActionButton* _fightAction;
    ActionButton* _finishAction;
    ActionButton* _playerInfo;
};
}
#endif // PLAYERITEMS_H
